//
//  LoginViewController.m
//  07-UITabBarController-拉勾
//
//  Created by LL.F on 16/7/23.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginView.h"

@interface LoginViewController ()
/* 拉勾图片 */
@property (nonatomic, strong) UIImageView *lagouImageView;
/* 模糊效果 */
@property (nonatomic, strong) UIVisualEffectView *effectView;
/* 自定义输入框view--登录界面 */
@property (nonatomic, strong) LoginView *userView;
/* 取消按钮 */
@property (nonatomic, strong) UIButton *cancelButton;
/* "问号"按钮 */
@property (nonatomic, strong) UIButton *questionButton;
/* "忘记密码"按钮 */
@property (nonatomic, strong) UIButton *forgetPasswordButton;
/* "登录"按钮 */
@property (nonatomic, strong) UIButton *loginButton;
/* "注册拉勾"按钮 */
@property (nonatomic, strong) UIButton *registerLagouButton;
/* 自定义输入框view--注册界面 */
@property (nonatomic, strong) LoginView *registerView;
/* "拉勾用户协议"按钮 */
@property (nonatomic, strong) UIButton *protocolButton;
/* "注册"按钮 */
@property (nonatomic, strong) UIButton *registerButton;
/* "返回登录"按钮 */
@property (nonatomic, strong) UIButton *returnLoginButton;

/* 协议图片 */
@property (nonatomic, strong) UIImageView *protocolImageView;
/* 协议标签 */
@property (nonatomic, strong) UILabel *protocolLabel;
/* 注册界面返回按钮 */
@property (nonatomic, strong) UIButton *returnButton;
/* "下一步"按钮 */
@property (nonatomic, strong) UIButton *nextButton;
/* "点击这里"按钮 */
@property (nonatomic, strong) UIButton *clickThereButton;
/* 自定义输入框view--注册界面 */
@property (nonatomic, strong) LoginView *verifyView;
/* "邮箱找回密码"标签 */
@property (nonatomic, strong) UILabel *emailLabel;

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 背景图
    UIImageView *mainImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
    mainImageView.image = [UIImage imageNamed:@"welcome_2"];
    [self.view addSubview:mainImageView];
    
    // 拉勾图片
    self.lagouImageView = [[UIImageView alloc] initWithFrame:CGRectMake(134, 120, 103, 163)];
    _lagouImageView.image = [UIImage imageNamed:@"logo_lagou"];
    [self.view addSubview:_lagouImageView];
    
    


    
    LoginView *userView = [[LoginView alloc] initWithFrame:CGRectMake(15, 320, 345, 37)];
    [self.view addSubview:userView];
    LoginView *passwordView = [[LoginView alloc] initWithFrame:CGRectMake(15, 320 + 37 + 1, 345, 37)];
    [passwordView.leftButton setImage:[[UIImage imageNamed:@"icon_password"] imageWithRenderingMode:1] forState:UIControlStateNormal];
    [self.view addSubview:passwordView];
    
    
    
//    // 模糊效果
//    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//    self.effectView = [[UIVisualEffectView alloc]initWithEffect:effect];
//    _effectView.frame = CGRectMake(0, 0, 345, 37);
//    _effectView.alpha = 0.5;
//    _effectView.tag = 2000;
//    [userView addSubview:_effectView];
    
    // 取消按钮
    self.cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _cancelButton.frame = CGRectMake(280, 25, 100, 30);
    [_cancelButton setImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:1]forState:UIControlStateNormal];
    [_cancelButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(didClickedCancelButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_cancelButton];
    
    // 新建"问号"按钮
    _questionButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _questionButton.frame = CGRectMake(285, 410, 20, 20);
    [_questionButton setImage:[[UIImage imageNamed:@"wenhao.png"] imageWithRenderingMode:1] forState:UIControlStateNormal];
    [_effectView addSubview:_questionButton];
    
    // "忘记密码"按钮
    self.forgetPasswordButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _forgetPasswordButton.frame = CGRectMake(305, 410, 60, 20);
    [_forgetPasswordButton setTitle:@"忘记密码" forState:UIControlStateNormal];
    [_forgetPasswordButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _forgetPasswordButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:_forgetPasswordButton];
    
    // "登录"按钮
    self.loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _loginButton.frame = CGRectMake(10, 470, 355, 40);
    _loginButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.69 blue:0.53 alpha:1.00];
    
    [_loginButton setTitle:@"登 录" forState:UIControlStateNormal];
    
    [_loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _loginButton.layer.cornerRadius = 2;
    [self.view addSubview:_loginButton];
    
    // "注册拉勾"按钮
    self.registerLagouButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _registerLagouButton.frame = CGRectMake(10, 540, 355, 40);
    [_registerLagouButton setTitle:@"注册拉勾" forState:UIControlStateNormal];
    [_registerLagouButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_registerLagouButton addTarget:self action:@selector(didClickedRegisterLagouButton) forControlEvents:UIControlEventTouchUpInside];
    _registerLagouButton.layer.borderWidth = 1;
    _registerLagouButton.layer.borderColor = [UIColor colorWithRed:0.00 green:0.65 blue:0.50 alpha:1.00].CGColor;
    _registerLagouButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.65 blue:0.50 alpha:1.00];
    _registerLagouButton.alpha = 0.5;
    _registerLagouButton.tag = 3000;
    [self.view addSubview:_registerLagouButton];


    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    [self.view endEditing:YES];
}
// 文本框开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
    
    //    [self removeSomeControlAndAddNew];
//    [self.view addSubview:_loginView];
    // 新建"忘记密码"按钮
    _forgetPasswordButton.frame = CGRectMake(305, 410, 60, 20);
    [self.view addSubview:_forgetPasswordButton];
    
    
    // textField与button联动
    if (textField == [[self.view viewWithTag:1000] viewWithTag:1002]) {
        UIButton *leftButton = [[self.view viewWithTag:1000] viewWithTag:1001];
        [leftButton setImage:[[UIImage imageNamed:@"icon_username_select"]imageWithRenderingMode:1] forState:UIControlStateNormal];
        
    } else if (textField == [[self.view viewWithTag:1000] viewWithTag:1003]) {
        
        UIButton *leftButton = [[self.view viewWithTag:1000] viewWithTag:1004];
        [leftButton setImage:[[UIImage imageNamed:@"icon_password_select"]imageWithRenderingMode:1] forState:UIControlStateNormal];
        
    }
    
}
#pragma mark 用户名按钮点击事件
- (void)didLeftButton
{
    
    if (_isClickingUserButton == NO) {
        UIButton *leftButton = [[self.view viewWithTag:1000] viewWithTag:1001];
        [leftButton setImage:[[UIImage imageNamed:@"icon_username_select"]imageWithRenderingMode:1] forState:UIControlStateNormal];
        _isClickingUserButton = YES;
        
    } else {
        UIButton *leftButton = [[self.view viewWithTag:1000] viewWithTag:1001];
        [leftButton setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
        _isClickingUserButton = NO;
    }
    
}
#pragma mark 密码按钮点击事件
- (void)didLeftDownButton
{
    if (_isClickingPasswordButton == NO) {
        UIButton *leftDownButton = [[self.view viewWithTag:1000] viewWithTag:1003];
        [leftDownButton setImage:[[UIImage imageNamed:@"icon_password_select"]imageWithRenderingMode:1] forState:UIControlStateNormal];
        _isClickingPasswordButton = YES;
        
    } else {
        UIButton *leftDownButton = [[self.view viewWithTag:1000] viewWithTag:1003];
        [leftDownButton setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
        _isClickingPasswordButton = NO;
        
    }
    
}
#pragma mark --移除无关控件并添加新控件
- (void)removeSomeControlAndAddNew:(UIButton *)button
{
    
    // 移除控件
    if (button == [self.view viewWithTag:3000]) {
        
        NSArray *array = [NSArray array];
        array = @[ _forgetPasswordButton, _questionButton, _loginButton, _registerLagouButton];
        [array makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
    } if (button == [self.view viewWithTag:4000]) {
        
        NSArray *array = [NSArray array];
        array = @[_registerView, _returnLoginButton, _registerButton, _protocolImageView, _protocolLabel, _protocolButton];
        [array makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
    } if (button == [self.view viewWithTag:5000]) {
        
        NSArray *array = [NSArray array];
        array = @[_returnButton, _nextButton,_emailLabel, _clickThereButton, _verifyView];
        [array makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
    }
    
}

//#pragma mark --"注册拉勾"按钮的点击方法,完成注册界面
//- (void)didClickedRegisterLagouButton
//{
//    
//    // 移除无关控件
//    [self removeSomeControlAndAddNew:_registerLagouButton];
//    // 添加新的输入框view--注册界面
//    _registerView = [[LoginView alloc] initWithFrame:CGRectMake(10, 320, 355, 74)];
//    _registerView.rightTextField.text = @" 请输入手机号";
//    _registerView.rightDownTextField.text = @" 请输入验证码";
//    _registerView.layer.cornerRadius = 2;
//    _registerView.layer.masksToBounds = YES;
//    [self.view addSubview:_registerView];
//    [_registerView.leftButton setImage:[[UIImage imageNamed:@"phone1"] imageWithRenderingMode:1] forState:UIControlStateNormal];
//    [_registerView.leftDownButton setImage:[[UIImage imageNamed:@"security1"] imageWithRenderingMode:1] forState:UIControlStateNormal];
//    
//    // 添加"注册"按钮
//    _registerButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _registerButton.frame = CGRectMake(10, 470, 355, 40);
//    _registerButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.69 blue:0.53 alpha:1.00];
//    [_registerButton setTitle:@"注 册" forState:UIControlStateNormal];
//    [_registerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [_registerButton addTarget:self action:@selector(didClickedRegisterButton) forControlEvents:UIControlEventTouchUpInside];
//    _registerButton.layer.cornerRadius = 2;
//    [self.view addSubview:_registerButton];
//    
//    // 添加"返回登录"按钮
//    self.returnLoginButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _returnLoginButton.frame = CGRectMake(10, 540, 355, 40);
//    [_returnLoginButton setTitle:@"返回登录" forState:UIControlStateNormal];
//    [_returnLoginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [_returnLoginButton addTarget:self action:@selector(didClickedReturnLoginButton) forControlEvents:UIControlEventTouchUpInside];
//    _returnLoginButton.layer.borderWidth = 1;
//    _returnLoginButton.layer.borderColor = [UIColor colorWithRed:0.00 green:0.65 blue:0.50 alpha:1.00].CGColor;
//    _returnLoginButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.65 blue:0.50 alpha:1.00];
//    _returnLoginButton.alpha = 0.5;
//    _returnLoginButton.tag = 4000;
//    [self.view addSubview:_returnLoginButton];
//    
//    //添加协议部分控件
//    self.protocolImageView = [[UIImageView alloc] initWithFrame:CGRectMake(70, 400, 20, 20)];
//    _protocolImageView.image = [UIImage imageNamed:@"protocol"];
//    [self.view addSubview:_protocolImageView];
//    
//    self.protocolLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 400, 120, 20)];
//    _protocolLabel.textColor = [UIColor whiteColor];
//    _protocolLabel.text = @"注册代表你已同意";
//    _protocolLabel.font = [UIFont systemFontOfSize:14];
//    [self.view addSubview:_protocolLabel];
//    
//    self.protocolButton = [UIButton buttonWithType:UIButtonTypeSystem];
//    _protocolButton.frame = CGRectMake(200, 400, 90, 20);
//    [_protocolButton setTitle:@"拉勾用户协议" forState:UIControlStateNormal];
//    _protocolButton.titleLabel.font = [UIFont systemFontOfSize:14];
//    [_protocolButton setTitleColor:[UIColor colorWithRed:0.00 green:0.65 blue:0.50 alpha:1.00] forState:UIControlStateNormal];
//    [self.view addSubview:_protocolButton];
//    
//}

- (void)didClickedCancelButton:(UIButton *)button
{

    [self dismissViewControllerAnimated:YES completion:nil];

    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
